package com.imut.controller;

import com.imut.entity.NovelChapter;
import com.imut.service.NovelChapterServices;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author jiangYaPeng
 * @Date 2025-07-08 17:09
 */
@RestController
@RequestMapping("/novel/NovelChapter")
public class NovelChapterController {
    @Autowired
    private NovelChapterServices novelChapterService;

    @GetMapping("/{novelId}")//阅读
    public ResponseEntity<List<NovelChapter>> getNovelById(@PathVariable Long novelId) {
        return ResponseEntity.ok(novelChapterService.selectById(novelId));
    }

    @GetMapping("/selectByChapterId/{id}")
    public ResponseEntity<NovelChapter> selectByChapterId(@PathVariable Long id) {
        return ResponseEntity.ok(novelChapterService.selectByChapterId(id));
    }


    @PostMapping
    public ResponseEntity<Boolean> insert(@RequestBody NovelChapter novelChapter) {
        return ResponseEntity.ok(novelChapterService.insert(novelChapter));
    }


    @PutMapping
    public ResponseEntity<Boolean> update(@RequestBody NovelChapter novelChapter) {
        return ResponseEntity.ok(novelChapterService.update(novelChapter));

    }

    @DeleteMapping("/{id}")
    public ResponseEntity<Boolean> delete(@PathVariable Long id) {
        return ResponseEntity.ok(novelChapterService.delete(id));
    }


}
